<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>NPS Docker 入门教程</title>
    <meta name="description" content="nps 一款轻量级、高性能、功能强大的内网穿透代理服务器。支持tcp、udp、socks5、http等几乎所有流量转发，可用来访问内网网站、本地支付接口调试、ssh访问、远程桌面，内网dns解析、内网socks5代理等">
    <meta name="keywords" content="docker,containers,tutorial">
    <link rel="stylesheet" type="text/css" href="../css/main.css?v=1.29.0">
    <link rel="stylesheet" type="text/css" href="../css/tocbot.css?v=1.29.0">
    <link rel="stylesheet" type="text/css" href="../css/media.css?v=1.29.0">
    <link rel="stylesheet" type="text/css" href="../css/sidebar.css?v=1.29.0">
    <link rel="stylesheet" type="text/css" href="../css/copy.css?v=1.29.0">
    <link rel="stylesheet" type="text/css" href="../css/demo-preview.css?v=1.29.0">
    <link rel="icon" href="../img/logo.svg" type="image/x-icon">
    <script src="../js/copy.js?v=1.29.0"></script>
    <script src="../js/dark-mode.js?v=1.29.0"></script>
    <script src="../js/markdown-style.js?v=1.29.0"></script>
  </head>
  <body id="idoctotop"><a href="#idoctotop" class="gototop">top</a>
    <header class="header">
      <article class="inner warpper"><a class="logo" href="../index.html"><svg viewBox="0 0 1280 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
            <path d="M699.88718 472.6h-132.2v-118.8h132.2v118.8z m0-408.6h-132.2v121.4h132.2V64z m156.4 289.6H724.08718v118.8h132.2v-118.8z m-312.6-144.2h-132.2v120.2h132.2v-120.2z m156.2 0h-132.2v120.2h132.2v-120.2z m553.6 200c-28.8-19.4-95.2-26.4-146.2-16.8-6.6-48-33.4-89.8-82.2-127.4l-28-18.6-18.6 28c-36.8 55.6-46.8 147.2-7.4 207.6-17.4 9.4-51.6 22.2-96.8 21.4H4.88718c-17.4 101.6 11.6 233.6 88 324.2 74.2 87.8 185.4 132.4 330.8 132.4 314.8 0 547.8-145 656.8-408.4 42.8 0.8 135.2 0.2 182.6-90.4 3-5 13.2-26.4 17-34.2l-26.6-17.8z m-1022.2-55.8h-132v118.8h132.2v-118.8z m156.2 0h-132.2v118.8h132.2v-118.8z m156.2 0h-132.2v118.8h132.2v-118.8z m-156.2-144.2h-132.2v120.2h132.2v-120.2z" fill="#0187D1"></path>
          </svg>
<span class="title">Docker 入门教程</span></a>
        <div class="content">
          <ul class="menu">
            <li><a href="../index.html" target="" class="">Home</a></li>
            <li><a href="https://wangchujiang.com/#/sponsor" target="__blank" class="">Sponsor</a></li>
          </ul><a href="https://github.com/jaywcjlove/docker-tutorial" target="_blank" rel="noopener noreferrer" title="Github" name="Github" class="github"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
              <path d="M9 19c-5 1.5-5-2.5-7-3m14 6v-3.87a3.37 3.37 0 0 0-.94-2.61c3.14-.35 6.44-1.54 6.44-7A5.44 5.44 0 0 0 20 4.77 5.07 5.07 0 0 0 19.91 1S18.73.65 16 2.48a13.38 13.38 0 0 0-7 0C6.27.65 5.09 1 5.09 1A5.07 5.07 0 0 0 5 4.77a5.44 5.44 0 0 0-1.5 3.78c0 5.42 3.3 6.61 6.44 7A3.37 3.37 0 0 0 9 18.13V22"></path>
            </svg></a>
          <dark-mode permanent=""></dark-mode>
        </div>
      </article>
    </header>
    <div class="warpper-content warpper sidebar">
      <div class="sidebar-border">
        <aside class="sidebar" role="navigation">
          <div>
            <a href="../index.html" class="">入门</a>
            <label>实践</label>
            <a href="../docker-compose.html" class="">Docker Compose</a>
            <a href="../elasticsearch.html" class="">ElasticSearch 搜索服务器</a>
            <a href="../gitlab/index.html" class="">Gitlab 代码仓库管理系统</a>
            <a href="../harbor.html" class="">Harbor</a>
            <a href="../mattermost.html" class="">Mattermost 聊天工具</a>
            <a href="../mysql.html" class="">MySQL 数据库</a>
            <a href="../nginx.html" class="">Nginx Web 服务器</a>
            <a href="index.html" class="active">NPS 内网穿透</a>
            <a href="../portainer.html" class="">Portainer Docker 管理</a>
            <a href="../postgres.html" class="">PostgreSQL 数据库</a>
            <a href="../penpot.html" class="">Penpot 设计和原型</a>
            <a href="../navidrome.html" class="">Navidrome 音乐服务器</a>
            <a href="../rancher.html" class="">Rancher 容器管理平台</a>
            <a href="../redis.html" class="">Redis 数据库</a>
            <a href="../rocket.chat/index.html" class="">Rocket.Chat 聊天工具</a>
            <a href="../seaweedfs/index.html" class="">SeaweedFS 文件系统</a>
            <a href="../sourcegraph/index.html" class="">Sourcegraph 代码搜索引擎</a>
          </div>
        </aside>
      </div>
      <markdown-style theme-auto-switch-disabled="">
        <h1 id="nps"><a aria-hidden="true" tabindex="-1" href="#nps" class="anchor"><span class="icon icon-link"></span></a>NPS</h1>
        <p><a href="https://github.com/ehang-io/nps">nps</a> 一款轻量级、高性能、功能强大的内网穿透代理服务器。支持tcp、udp、socks5、http等几乎所有流量转发，可用来访问内网网站、本地支付接口调试、ssh访问、远程桌面，内网dns解析、内网socks5代理等</p>
        <h3 id="-搭建nps服务端"><a aria-hidden="true" tabindex="-1" href="#-搭建nps服务端" class="anchor"><span class="icon icon-link"></span></a>① 搭建NPS服务端</h3>
        <p>服务器搭建在拥有公网 <code>ip=150.106.195.110</code> 的服务器上。下载配置 <a href="https://github.com/ehang-io/nps/tree/master/conf">nps/conf</a>，将配置放在 <code>/opt/nps/conf</code> 目录下，下面我们使用 docker 部署 NPS 服务端：</p>
        <pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line line-number" line="1"><span class="token comment"># 创建 /opt/nps 目录存放配置文件</span>
</span><span class="code-line line-number" line="2"><span class="token function">mkdir</span> /opt/nps
</span><span class="code-line line-number" line="3"><span class="token comment"># 拉取 ffdfgdfg/nps 镜像</span>
</span><span class="code-line line-number" line="4"><span class="token function">docker</span> pull ffdfgdfg/nps
</span><span class="code-line line-number" line="5"><span class="token comment"># 运行 nps 容器，配置文件夹 conf 在 /opt/nps/conf 目录下</span>
</span><span class="code-line line-number" line="6"><span class="token function">docker</span> run <span class="token parameter variable">-d</span> <span class="token parameter variable">--name</span><span class="token operator">=</span>nps <span class="token parameter variable">--restart</span><span class="token operator">=</span>always <span class="token parameter variable">--net</span><span class="token operator">=</span>host <span class="token parameter variable">-v</span> /opt/nps/conf:/conf ffdfgdfg/nps
</span><span class="code-line line-number" line="7"><span class="token comment"># 查看日志</span>
</span><span class="code-line line-number" line="8"><span class="token function">docker</span> logs nps
</span></code><input type="hidden" value="# 创建 /opt/nps 目录存放配置文件
mkdir /opt/nps
# 拉取 ffdfgdfg/nps 镜像
docker pull ffdfgdfg/nps
# 运行 nps 容器，配置文件夹 conf 在 /opt/nps/conf 目录下
docker run -d --name=nps --restart=always --net=host -v /opt/nps/conf:/conf ffdfgdfg/nps
# 查看日志
docker logs nps
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <p>启动之后默认端口 <code>8080</code>，通过使用 <code>http://&#x3C;你服务器IP>:8080</code> 访问管理界面。</p>
        <p>
          <img src="001.png" alt="">
        </p>
        <p>使用用户名和密码登陆（默认<code>admin/123</code>，正式使用一定要更改，修改 <code>/opt/nps/conf/nps.conf</code> 配置文件中的 <code>web_password</code>），也可以在这里配置更改默认控制台管理平台端口（<code>web_port</code> = <code>8666</code>），通道端口更改 <code>bridge_port=8024</code></p>
        <p>记得在控制台开放端口，面板<strong>默认端口</strong>是 <code>8080</code>，与客户端<strong>通信端口</strong>是 <code>8024</code>。</p>
        <h3 id="-添加客户端"><a aria-hidden="true" tabindex="-1" href="#-添加客户端" class="anchor"><span class="icon icon-link"></span></a>② 添加客户端</h3>
        <p>
          <img src="002.png" alt="">
        </p>
        <p>
          <img src="003.png" alt="">
        </p>
        <p>
          <img src="004.png" alt="">
        </p>
        <p>注意：客户端命令 <code>./npc -server=150.106.195.110:8024 -vkey=&#x3C;唯一验证密钥> -type=tcp</code> 中的 <code>唯一验证密钥</code> 用于客户端安装需要使用</p>
        <h3 id="-客户端安装使用"><a aria-hidden="true" tabindex="-1" href="#-客户端安装使用" class="anchor"><span class="icon icon-link"></span></a>③ 客户端安装使用</h3>
        <p>客户端安装在你需要穿透的内网服务器(电脑)上。</p>
        <pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line line-number" line="1"><span class="token comment"># 创建 /opt/nps 目录存放配置文件</span>
</span><span class="code-line line-number" line="2"><span class="token function">mkdir</span> /opt/npc
</span><span class="code-line line-number" line="3"><span class="token comment"># 拉取 ffdfgdfg/nps 镜像</span>
</span><span class="code-line line-number" line="4"><span class="token function">docker</span> pull ffdfgdfg/npc
</span><span class="code-line line-number" line="5"><span class="token comment"># 运行 npc 容器，按提示改好命令，如下图所示</span>
</span><span class="code-line line-number" line="6"><span class="token comment"># 唯一验证密钥在管理界面中获取</span>
</span><span class="code-line line-number" line="7"><span class="token function">docker</span> run <span class="token parameter variable">-d</span> <span class="token parameter variable">--name</span><span class="token operator">=</span>npc <span class="token parameter variable">--restart</span><span class="token operator">=</span>always <span class="token parameter variable">--net</span><span class="token operator">=</span>host ffdfgdfg/npc <span class="token parameter variable">-server</span><span class="token operator">=</span><span class="token operator">&#x3C;</span>ip:port<span class="token operator">></span> <span class="token parameter variable">-vkey</span><span class="token operator">=</span><span class="token operator">&#x3C;</span>web界面中显示的密钥<span class="token operator">></span> <span class="token operator">&#x3C;</span>以及一些其他参数<span class="token operator">></span>
</span><span class="code-line line-number" line="8"><span class="token comment"># 示例</span>
</span><span class="code-line line-number" line="9"><span class="token function">docker</span> run <span class="token parameter variable">-d</span> <span class="token parameter variable">--name</span><span class="token operator">=</span>npc <span class="token parameter variable">--restart</span><span class="token operator">=</span>always <span class="token parameter variable">--net</span><span class="token operator">=</span>host ffdfgdfg/npc <span class="token parameter variable">-server</span><span class="token operator">=</span><span class="token number">150.106</span>.195.110:8024 <span class="token parameter variable">-vkey</span><span class="token operator">=</span><span class="token operator">&#x3C;</span>唯一验证密钥<span class="token operator">></span>
</span><span class="code-line line-number" line="10"><span class="token comment"># 查看日志</span>
</span><span class="code-line line-number" line="11"><span class="token function">docker</span> logs npc
</span></code><input type="hidden" value="# 创建 /opt/nps 目录存放配置文件
mkdir /opt/npc
# 拉取 ffdfgdfg/nps 镜像
docker pull ffdfgdfg/npc
# 运行 npc 容器，按提示改好命令，如下图所示
# 唯一验证密钥在管理界面中获取
docker run -d --name=npc --restart=always --net=host ffdfgdfg/npc -server=<ip:port> -vkey=<web界面中显示的密钥> <以及一些其他参数>
# 示例
docker run -d --name=npc --restart=always --net=host ffdfgdfg/npc -server=150.106.195.110:8024 -vkey=<唯一验证密钥>
# 查看日志
docker logs npc
"><div onclick="copied(this)" class="copied"><svg class="octicon-copy" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg><svg class="octicon-check" aria-hidden="true" viewBox="0 0 16 16" fill="currentColor" height="12" width="12"><path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path></svg></div></pre>
        <p>服务运行起来，这样客户端就连接到了 NPS 的服务端了</p>
        <p>
          <img src="005.png" alt="">
        </p>
        <h3 id="-建立内网穿透隧道"><a aria-hidden="true" tabindex="-1" href="#-建立内网穿透隧道" class="anchor"><span class="icon icon-link"></span></a>④ 建立内网穿透隧道</h3>
        <p>
          <img src="006.png" alt="">
        </p>
        <p>
          <img src="007.png" alt="">
        </p>
        <p>假设我们要穿透局域网 MySQL 数据库，在 <code>目标 (IP:端口)</code> 配置内网 MySQL IP:端口 <code>192.168.188.222:3306</code>，在外网访问的端口 <code>服务端端口</code> 配置 <code>33066</code></p>
        <p>
          <img src="008.png" alt="">
        </p>
        <p>配置完成之后你可以使用公网 <code>ip=150.106.195.110</code> IP 地址 和端口 <code>33066</code> 连接到你内网的机器中的数据库。</p>
        <p>到这里就完成了，你可以自己继续研究一下更多的功能，也可以看看官方的<a href="https://ehang-io.github.io/nps/#/">说明文档</a>。</p>
        <h3 id="-新建-socks5-代理"><a aria-hidden="true" tabindex="-1" href="#-新建-socks5-代理" class="anchor"><span class="icon icon-link"></span></a>⑤ 新建 Socks5 代理</h3>
        <p>通过 Socks5 代理可以访问内网任意服务，不必建立一个个的内网穿透隧道。在设置代理之前确保 <code>客户端</code> 建立好，并且 <code>链接</code> 状态为 <code>在线</code>。</p>
        <p>
          <img src="009.png" alt="">
        </p>
        <p>
          <img src="010.png" alt="">
        </p>
        <p>
          <img src="011.png" alt="">
        </p>
        <p>在建立好 Socks5 代理之后，需要使用 <a href="https://www.proxifier.com/"><code>proxifier</code></a> 配置代理访问公司内网</p>
        <p>
          <img src="012.png" alt="">
        </p>
        <h3 id="相关链接"><a aria-hidden="true" tabindex="-1" href="#相关链接" class="anchor"><span class="icon icon-link"></span></a>相关链接</h3>
        <ul>
          <li>官网文档：<a href="https://ehang-io.github.io/nps/">https://ehang-io.github.io/nps/</a></li>
          <li>GitHub：<a href="https://github.com/ehang-io/nps">https://github.com/ehang-io/nps</a></li>
        </ul>
        <div class="previous"><a class="prev" href="../nginx.html"><svg viewBox="0 0 1024 1024" width="16" height="16" fill="currentColor">
              <path d="M842.666667 864c-8.533333 0-14.933333-2.133333-21.333334-8.533333l-341.333333-309.333334c-6.4-6.4-10.666667-14.933333-10.666667-23.466666 0-8.533333 4.266667-17.066667 10.666667-23.466667l341.333333-309.333333c12.8-12.8 34.133333-10.666667 44.8 2.133333 12.8 12.8 10.666667 34.133333-2.133333 44.8L548.266667 522.666667l315.733333 285.866666c12.8 10.666667 14.933333 32 2.133333 44.8-6.4 6.4-14.933333 10.666667-23.466666 10.666667z"></path>
              <path d="M512 864c-8.533333 0-14.933333-2.133333-21.333333-8.533333L149.333333 546.133333c-6.4-6.4-10.666667-14.933333-10.666666-23.466666 0-8.533333 4.266667-17.066667 10.666666-23.466667L490.666667 189.866667c12.8-12.8 34.133333-10.666667 44.8 2.133333 12.8 12.8 10.666667 34.133333-2.133334 44.8L217.6 522.666667 533.333333 808.533333c12.8 12.8 14.933333 32 2.133334 44.8-6.4 6.4-14.933333 10.666667-23.466667 10.666667z"></path>
            </svg>
<span>Nginx Web 服务器
</span></a><a class="next" href="../portainer.html"><span>Portainer Docker 管理
</span><svg viewBox="0 0 1024 1024" width="16" height="16" fill="currentColor">
              <path d="M544 522.666667c0-8.533333-4.266667-17.066667-10.666667-23.466667L192 189.866667c-12.8-12.8-34.133333-10.666667-44.8 2.133333-12.8 12.8-10.666667 34.133333 2.133333 44.8l315.733334 285.866667L149.333333 808.533333c-12.8 12.8-14.933333 32-2.133333 44.8 6.4 6.4 14.933333 10.666667 23.466667 10.666667 8.533333 0 14.933333-2.133333 21.333333-8.533333l341.333333-309.333334c6.4-6.4 10.666667-14.933333 10.666667-23.466666z"></path>
              <path d="M864 499.2l-341.333333-309.333333c-12.8-12.8-34.133333-10.666667-44.8 2.133333-12.8 12.8-10.666667 34.133333 2.133333 44.8l315.733333 285.866667-315.733333 285.866666c-12.8 12.8-14.933333 32-2.133333 44.8 6.4 6.4 14.933333 10.666667 23.466666 10.666667 8.533333 0 14.933333-2.133333 21.333334-8.533333l341.333333-309.333334c6.4-6.4 10.666667-14.933333 10.666667-23.466666 0-8.533333-4.266667-17.066667-10.666667-23.466667z"></path>
            </svg></a></div>
        <section class="article-footer"><a href="https://github.com/jaywcjlove/docker-tutorial/tree/master/docs/nps/README.md" class="edit-button" target="_blank" rel="noopener noreferrer"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
              <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"></path>
            </svg>
<span>Edit this page on GitHub</span>
</a><span class="atime">2022/04/20</span></section>
      </markdown-style>
      <nav class="tocs">
        <aside class="inner toc">
          <ol class="tocs-list">
            <li><a href="#-搭建nps服务端" class="tocs-link">① 搭建NPS服务端</a></li>
            <li><a href="#-添加客户端" class="tocs-link">② 添加客户端</a></li>
            <li><a href="#-客户端安装使用" class="tocs-link">③ 客户端安装使用</a></li>
            <li><a href="#-建立内网穿透隧道" class="tocs-link">④ 建立内网穿透隧道</a></li>
            <li><a href="#-新建-socks5-代理" class="tocs-link">⑤ 新建 Socks5 代理</a></li>
            <li><a href="#相关链接" class="tocs-link">相关链接</a></li>
          </ol>
        </aside>
      </nav>
    </div>
    <script src="../js/demo-preview.js?v=1.29.0"></script>
    <div class="footer warpper">
      <a href="https://wangchujiang.com/#/app" target="_blank">App</a> •
      <a href="https://wangchujiang.com/#/projects" target="_blank">Projects</a> •
      <a href="https://wangchujiang.com/#/sponsor" target="_blank">Sponsor</a> •
      <a href="https://wangchujiang.com/#/app" target="_blank">More Apps</a><br><br>Released under the MIT License. Copyright © 2024 <a href="https://wangchujiang.com/#/about" target="_blank">Kenny Wong</a><br>Generated by <a href="https://github.com/jaywcjlove/idoc" target="_blank">idoc</a> v1.29.0
    </div>
    <script src="../js/tocbot.js?v=1.29.0"></script>
  </body>
</html>
